﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AspValidation.Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script language="javascript" type="text/javascript">
    function Validation(source, arguments) {
        arguments.IsValid = document.getElementById("iAcceptCheckBox").checked
    }
    function GendreChanged() {
        var radioButtons = document.getElementsByName("gendreDynamic");
        for (var x = 0; x < radioButtons.length; x++) {
            if (radioButtons[x].checked) {
                if (radioButtons[x].value == "Male") {
                    document.getElementById("femalePanelDynamic").style.display = 'none';
                    document.getElementById("malePanelDynamic").style.display = 'block';
                }
                else {
                    document.getElementById("malePanelDynamic").style.display = 'none';
                    document.getElementById("femalePanelDynamic").style.display = 'block';
                } 
            }
        } 
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <link rel="Stylesheet" type="text/css" href="Site.css"/>
    <title></title>
</head>
<body>
    <form id="mainForm" runat="server">
        <div>
            <asp:Label ID="userNameLbl" runat="server" Text="User name: "></asp:Label>
            <asp:TextBox ID="userNameTxt" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidatorUserName" runat="server"
                ControlToValidate="userNameTxt"
                Display="Dynamic"
                ErrorMessage="User name is required"
                ValidationGroup="Logon"
                ForeColor="Red">
            </asp:RequiredFieldValidator>
            <br/>
            <asp:Label ID="passLbl" runat="server" Text="Password: "></asp:Label>
            <asp:TextBox TextMode="Password" ID="passTxt" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidatorPass" runat="server"
                ControlToValidate="passTxt"
                Display="Dynamic"
                ErrorMessage="Password is required"
                ValidationGroup="Logon"
                ForeColor="Red">
            </asp:RequiredFieldValidator>
            <br/>
            <asp:Label ID="repPassLbl" runat="server" Text="Repeat Password: "></asp:Label>
            <asp:TextBox TextMode="Password" ID="repPassTxt" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidatorRepPass" runat="server"
                ControlToValidate="repPassTxt"
                Display="Dynamic"
                ErrorMessage="Repeate Password is required"
                ValidationGroup="Logon"
                ForeColor="Red">
            </asp:RequiredFieldValidator>
            <asp:CompareValidator ID="CompareValidatorPass" runat="server"
                ErrorMessage="Repeated password is different" 
                ControlToValidate="passTxt"
                ControlToCompare="repPassTxt"
                ValidationGroup="Logon"
                Display="Dynamic"
                ForeColor="Red">
            </asp:CompareValidator>
            <br/>
            <asp:Label ID="fNameLbl" runat="server" Text="First name: "></asp:Label>
            <asp:TextBox ID="fNameTxt" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidatorFirstName" runat="server"
                ControlToValidate="fNameTxt"
                Display="Dynamic"
                ErrorMessage="First name is required"
                ValidationGroup="Personal"
                ForeColor="Red">
            </asp:RequiredFieldValidator>
            <br/>
            <asp:Label ID="lNameLbl" runat="server" Text="Last name: "></asp:Label>
            <asp:TextBox ID="lNameTxt" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidatorLastName" runat="server"
                ControlToValidate="lNameTxt"
                Display="Dynamic"
                ErrorMessage="Last name is required"
                ValidationGroup="Personal"
                ForeColor="Red">
            </asp:RequiredFieldValidator>
            <br/>
            <asp:Label ID="ageLbl" runat="server" Text="Age: "></asp:Label>
            <asp:TextBox ID="ageTxt" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidatorAge" runat="server"
                ControlToValidate="ageTxt"
                Display="Dynamic"
                ErrorMessage="Age is required"
                ValidationGroup="Personal"
                ForeColor="Red">
            </asp:RequiredFieldValidator>
            <asp:RangeValidator ID="RangeValidatorAge" runat="server"
                ErrorMessage="Invalid Age" 
                ControlToValidate="ageTxt"
                Display="Dynamic"
                ForeColor="Red"
                Type="Integer"
                ValidationGroup="Personal"
                MinimumValue="18"
                MaximumValue="81">
             </asp:RangeValidator>
             <br/>
            <asp:Label ID="emailLbl" runat="server" Text="Email: "></asp:Label>
            <asp:TextBox ID="emailTxt" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidatorEmail" runat="server"
                ControlToValidate="emailTxt"
                Display="Dynamic"
                ErrorMessage="Email is required"
                ValidationGroup="Personal" 
                ForeColor="Red">
            </asp:RequiredFieldValidator>
            <asp:RegularExpressionValidator ID="RegularExpressionValidatorEmail" runat="server"
                ControlToValidate="emailTxt"
                Display="Dynamic"
                ErrorMessage="Email is invalid"
                ValidationGroup="Personal" 
                ForeColor="Red"
                ValidationExpression="[a-zA-Z][a-zA-Z0-9\-\.]+[a-zA-Z]@[a-zA-Z][a-zA-Z0-9\-\.]+[a-zA-Z]+\.[a-zA-Z]{2,4}" >
            </asp:RegularExpressionValidator>
            <br/>
            <asp:Label ID="addressLbl" runat="server" Text="Address: "></asp:Label>
            <asp:TextBox ID="addressTxt" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidatorAddress" runat="server"
                ControlToValidate="addressTxt"
                Display="Dynamic"
                ErrorMessage="Address is required"
                ValidationGroup="Address" 
                ForeColor="Red">
            </asp:RequiredFieldValidator>
            <br/>
            <asp:Label ID="phoneLbl" runat="server" Text="Phone: "></asp:Label>
            <asp:TextBox ID="phoneTxt" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                ControlToValidate="phoneTxt"
                Display="Dynamic"
                ErrorMessage="Phone is required"
                ValidationGroup="Address" 
                ForeColor="Red">
            </asp:RequiredFieldValidator>
            <br/>
            <asp:Label ID="iAcceptLbl" runat="server" Text="I accept "></asp:Label>
            <asp:CheckBox ID="iAcceptCheckBox" runat="server" />
            <asp:CustomValidator ID="CustomValidatorCheckBox" runat="server"
                ErrorMessage="You should accept the terms"
                Text="You should accept the terms"
                ForeColor="Red"
                OnServerValidate="custom_ServerValidate"
                ClientValidationFunction="Validation">
            </asp:CustomValidator>
            <br/>
            <asp:RadioButtonList ID="Gender" runat="server" 
                AutoPostBack="true"
                onselectedindexchanged="Gender_SelectedIndexChanged">
                <asp:ListItem Text="Male" />
                <asp:ListItem Text="Female" />
            </asp:RadioButtonList>
            <asp:Panel ID="malePanel" runat="server" Visible="false"> 
                <asp:CheckBoxList ID="carsCheckBox" runat="server" >
                    <asp:ListItem Text="BMW" />
                    <asp:ListItem Text="Toyota" />
                    <asp:ListItem Text="VW" />
                    <asp:ListItem Text="Mercedes" />
                </asp:CheckBoxList>
            </asp:Panel>
            <asp:Panel ID="femalePanel" runat="server" Visible="false"> 
                <asp:DropDownList ID="coffees" runat="server">
                    <asp:ListItem Text="New Brazil" />
                    <asp:ListItem Text="Lavazza" />
                    <asp:ListItem Text="Some Other" />
                    <asp:ListItem Text="Turkish" />
                </asp:DropDownList>
            </asp:Panel>
            Dynamic Gendre selection:
            <br/>
            <asp:RadioButtonList ID="gendreDynamic" runat="server" onChange="GendreChanged()" >
                <asp:ListItem Text="Male" />
                <asp:ListItem Text="Female" />
            </asp:RadioButtonList>
            <asp:Panel ID="malePanelDynamic" runat="server"> 
                <asp:CheckBoxList ID="carsDynamic" runat="server" >
                    <asp:ListItem Text="BMW" />
                    <asp:ListItem Text="Toyota" />
                    <asp:ListItem Text="VW" />
                    <asp:ListItem Text="Mercedes" />
                </asp:CheckBoxList>
            </asp:Panel>
            <asp:Panel ID="femalePanelDynamic" runat="server"> 
                <asp:DropDownList ID="coffeesDynamic" runat="server">
                    <asp:ListItem Text="New Brazil" />
                    <asp:ListItem Text="Lavazza" />
                    <asp:ListItem Text="Some Other" />
                    <asp:ListItem Text="Turkish" />
                </asp:DropDownList>
            </asp:Panel>
            <br/>
            <asp:Button ID="SubmitBtn" runat="server" Text="Submit" onclick="submitBtn_Click" />

            <asp:ValidationSummary ID="myVS" runat="server"></asp:ValidationSummary>
        </div>
    </form>

</body>
</html>
